//
//  MatchVC.swift
//  JTYP
//
//  Created by Groot on 2017/12/9.
//  Copyright © 2017年 inspur. All rights reserved.
//

class MomentsVC: TransparentNavBarVC {
    
    let scrollBarItems = [ScrollBarItem.init(itemName: "我的朋友圈"),
                          ScrollBarItem.init(itemName: "身边朋友圈")]
    // 导航栏高度
    let topBarHeight: CGFloat = 110
    
    @IBOutlet weak var mainScrollView: UIScrollView!
    
    private var scrollbarView: ScrollBarView = {
        var v = ScrollBarView()
        return v
    }()
    
    private var topView: CustomTopView = {
        var v: CustomTopView = Bundle.main.loadNibNamed("CustomTopView", owner: nil, options: nil)?.first as! CustomTopView
        v.setTitle(title: "朋友圈", imgName: "pyq_top")
        return v
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if #available(iOS 11.0, *) {
            mainScrollView.contentInsetAdjustmentBehavior = .never;
        }else {
            self.automaticallyAdjustsScrollViewInsets = false;
        }
        
        setupMainScrollView()
        setupTopView()
        setupScrollBarView()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    func setupMainScrollView() {
        mainScrollView.showsVerticalScrollIndicator = false
        mainScrollView.bounces = false
        mainScrollView.backgroundColor = UIColor.clear
    }
    
    func setupTopView() {
        mainScrollView.addSubview(topView)
        topView.snp.makeConstraints { (make) in
            make.height.equalTo(topBarHeight)
            make.top.equalToSuperview()
            make.width.equalTo(SCREEN_WIDTH)
        }
    }
    
    func setupScrollBarView() {
        
        var vcs: [PageCollectionVC] = []
        
        for i in 0 ..< scrollBarItems.count {
            let layout = UICollectionViewFlowLayout()
            //layout.scrollDirection = .vertical
            layout.minimumLineSpacing = 1
            layout.minimumInteritemSpacing = 1
            
            let vc = PageCollectionVC.init(collectionViewLayout: layout)
            vcs.append(vc)
        }
        
        // viewcontrollers
        mainScrollView.addSubview(scrollbarView)
        scrollbarView.snp.makeConstraints { (make) in
            make.top.equalTo(topView.snp.bottom)
            make.width.equalTo(SCREEN_WIDTH)
            make.height.equalTo(self.view.bounds.height - topBarHeight)
        }
        scrollbarView.layoutIfNeeded()
        scrollbarView.normalTitleColor = .darkGray
        scrollbarView.selectedTitleColor = DefaultColor.green
        scrollbarView.scrollBarTitleFontSize = 17.0
        scrollbarView.backgroundColor = .clear
        scrollbarView.setScrollBarItems(items: scrollBarItems, and: vcs, style: .average)
        scrollbarView.scrollBar.backgroundColor = .clear
        scrollbarView.updateScrollBarConstraints()
    }
}

